//被代理对象
let data = {
    msg: 'hello',
    count: 0,
    user:{
        name:'jack'
    }
}
//模板对象
// let handler = {
//     get: function (target, key) {
//         console.log('get >>>>', target[key]);
//         return target[key]
//     },
//     set: function (target, key, value) {
//         console.log('set >>>> ', target, ' key :', key, ' value :', value);
//         target[key] = value
//     }
// }
const handler = {
    get(target, key, recevier) {
        console.log('get >>>>', typeof target[key]);
        // if (typeof target[key] === 'object') {
        //     addSubProxy(target[key])
        // }
        return Reflect.get(target, key, recevier)
    },
    set: function(target, key, value) {
        console.log('set >>>> ', target, ' key :', key, ' value :', value);
        Reflect.set(target, key, value)
    }
}

function createProxy(obj) {
    return addSubProxy(obj)
}

function addSubProxy(subObj) {
    return new Proxy(subObj, handler)
}
//创建代理对象vm
let vm = createProxy(data) //new Proxy(data, handler)
vm.count = 10
// console.log('msg : ', vm.msg, ' count :',vm.count)
// vm.user.name = 'rose'
